package com.demo11.d17_03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * @Author: root
 * @Date: 2018/12/4 17:55
 */
public class Client {
    public static void main(String[] args) throws IOException {
        /**
         * 使用ServerSocket和Socket建立连接
         */
        Socket socket = new Socket("127.0.0.1", 30000);
        /**
         *getInputStream()：返回Socket对象对应的输入流，让程序通过该输入流从socket中取出数据
         */
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line = br.readLine();
        System.out.println("来自服务器的数据：" + line);
        br.close();
        socket.close();
    }
}
